package com.jmpt.fangbohui.utils;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharePerfencesUtils {
	private static Context mContext;
	private static SharedPreferences sp;
	public static String ENTER_HOUSE = "enter_house";
	private static void init(String name){
		sp = null;
		sp = mContext.getSharedPreferences(name,Context.MODE_PRIVATE);
	}
	
	
	public static List<String> getEnterHouseCacheData(){
		init(ENTER_HOUSE);
		List<String> cacheData = new ArrayList<String>();
		cacheData.add(sp.getString("H_SaleOrRent", ""));
		cacheData.add(sp.getString("LXID", ""));
		cacheData.add(sp.getString("H_Num", ""));
		cacheData.add(sp.getString("H_Title", ""));
		cacheData.add(sp.getString("ProvinceID", ""));
		cacheData.add(sp.getString("CityID", ""));
		cacheData.add(sp.getString("ZoneID", ""));
		cacheData.add(sp.getString("AreaID", ""));
		cacheData.add(sp.getString("H_DZ", ""));
		cacheData.add(sp.getString("H_MJ", ""));
		cacheData.add(sp.getString("H_SalePrice", ""));
		cacheData.add(sp.getString("H_paymentSale", ""));
		cacheData.add(sp.getString("H_paymentRent", ""));
		cacheData.add(sp.getString("H_RentPrice", ""));
		cacheData.add(sp.getString("H_Room", ""));
		cacheData.add(sp.getString("H_Hall", ""));
		cacheData.add(sp.getString("ZXID", ""));
		cacheData.add(sp.getString("H_CX", ""));
		
		sp.edit().putBoolean("isCache", false).commit();
		return cacheData;
	}
	
	public static boolean checkEnterHouseCacheData(){
		init(ENTER_HOUSE);
		
		return sp.getBoolean("isCache", false);
	}
	
	public static void setEnterHouseCacheData(List<String> cacheData){
		init(ENTER_HOUSE);
		
		Editor edit = sp.edit();
		edit.putString("H_SaleOrRent", cacheData.get(0));
		edit.putString("LXID", cacheData.get(1));
		edit.putString("H_Num", cacheData.get(2));
		edit.putString("H_Title", cacheData.get(3));
		edit.putString("ProvinceID", cacheData.get(4));
		edit.putString("CityID", cacheData.get(5));
		edit.putString("ZoneID", cacheData.get(6));
		edit.putString("AreaID", cacheData.get(7));
		edit.putString("H_DZ", cacheData.get(8));
		edit.putString("H_MJ", cacheData.get(9));
		edit.putString("H_SalePrice", cacheData.get(10));
		edit.putString("H_paymentSale", cacheData.get(11));
		edit.putString("H_paymentRent", cacheData.get(12));
		edit.putString("H_RentPrice", cacheData.get(13));
		edit.putString("H_Room", cacheData.get(14));
		edit.putString("H_Hall", cacheData.get(15));
		edit.putString("ZXID", cacheData.get(16));
		edit.putString("H_CX", cacheData.get(17));
		edit.putBoolean("isCache",true);
		
		edit.commit();
	}

	public static void setUserCache(Context context,String phone,String password){
		SharedPreferences sp = context.getSharedPreferences("sp", Context.MODE_PRIVATE);
		sp.edit().putString("userPhone", phone).putString("userPassword", password).commit();
	}
	public static void setBrokerCache(Context context,String phone,String password){
		SharedPreferences sp = context.getSharedPreferences("sp", Context.MODE_PRIVATE);
		sp.edit().putString("brokerPhone", phone).putString("brokerPassword", password).commit();
	}
	public static List<String> getUserCache(Context context){
		List<String> list = new ArrayList<String>();
		SharedPreferences sp = context.getSharedPreferences("sp", Context.MODE_PRIVATE);
		list.add(sp.getString("userPhone", ""));
		list.add(sp.getString("userPassword", ""));
		return list;
	}
	public static List<String> getBrokerCache(Context context){
		List<String> list = new ArrayList<String>();
		SharedPreferences sp = context.getSharedPreferences("sp", Context.MODE_PRIVATE);
		list.add(sp.getString("brokerPhone", ""));
		list.add(sp.getString("brokerPassword", ""));
		return list;
	}
}
